package com.godz.frontData.index3;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.index3DreamMapper;
import com.godz.pojo.index3Dream;
import org.springframework.web.bind.annotation.*;
import java.util.List;
//我的梦想
@RestController
public class dreamData {
    final
    index3DreamMapper dreamMapper;

    public dreamData(index3DreamMapper dreamMapper) {
        this.dreamMapper = dreamMapper;
    }

    @GetMapping("/index3/get/dream")
    public List<index3Dream> getDream(){
        return dreamMapper.queryAllDream();
    }
    //查询单个
    @GetMapping("/index3/get/dreamOne/{intId}")
    public index3Dream getOneDream(@PathVariable("intId") Integer integer) {
        return dreamMapper.selectOne(
                new QueryWrapper<index3Dream>().eq("id", integer)
        );
    }
    //增加一条
    @PostMapping("/index3/post/addDream")
    public String addDream(@RequestBody index3Dream dream) {
        dreamMapper.insert(dream);
        return "insert OK";
    }
    //修改一条
    @PostMapping("/index/post/editDream")
    public String editDream(@RequestBody index3Dream dream) {
        QueryWrapper<index3Dream> wrapper = new QueryWrapper<>();
        wrapper.eq("id", dream.getId());

        index3Dream dream1 = new index3Dream();
        dream1.setDreamCon(dream.getDreamCon());
        dream1.setDreamTitle(dream.getDreamTitle());
        dream1.setDreamImg(dream.getDreamImg());

        dreamMapper.update(dream1, wrapper);
        return "Update OK";
    }
    //删除一条
    @GetMapping("/index3/get/deleteDream/{id}")
    public String deleteDream(@PathVariable("id") Integer integer) {
        dreamMapper.deleteById(integer);
        return "Delete Ok";
    }

}
